package com.eselect.config;

import com.eselect.mq.consumer.DlxConsumer;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfiguration {



    public static final String SIMPLE_EXCHANGE_DEFAULT = "simple.default";
    public static final String SIMPLE_QUEUE_DEFAULT = "simple.default.queue1";

    @Bean
    public DirectExchange directExchange(){
        return ExchangeBuilder.directExchange(SIMPLE_EXCHANGE_DEFAULT).durable(true).build();
    }

    @Bean
    public Queue simpleQueue1(){
        return QueueBuilder.durable(SIMPLE_QUEUE_DEFAULT).lazy()
                .deadLetterExchange(DlxConsumer.DLX_EXCHANGE)
                .deadLetterRoutingKey(DlxConsumer.DLX_ROUTING_KEY)
                .build();
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(simpleQueue1()).to(directExchange()).with("default");
    }
}
